#coding: utf-8
import sys, urllib, urllib2, json


def printContent(data, prefix = ""):
    if type(data) == type(list()):
        for i in data:
            printContent(i, prefix=prefix+2*' ')
    if type(data) == type(dict()):
        for i in data.keys():
            if type(data[i]) == type(0):
                print(prefix + i + ":" + str(data[i]))
            if type(data[i]) == type(u'hello'):
                print(prefix + i + ':' + data[i])
            if type(data[i]) == type(dict()):
                printContent(i, prefix=prefix+2*' ')
                printContent(data[i],prefix=prefix+2*' ')
            if type(data[i]) == type(list()):
                printContent(i, prefix=prefix+2*' ')
                printContent(data[i],prefix=prefix+2*' ')
    if type(data) == type(0):
        print(prefix + str(data))
    if type(data) == type(u'hello'):
        print(prefix + data)


url = 'http://apis.baidu.com/apistore/weatherservice/recentweathers?cityname=嘉定'
req = urllib2.Request(url)
req.add_header("apikey", "24d104dbf708b266d6f9ad4b45b0d50c")
resp = urllib2.urlopen(req)
content = resp.read()
if content:
    data = json.loads(content)['retData']
    print('Today:')
    today = data['today']
    for i in today.keys():
        if type(today[i]) != type(dict()) and type(today[i]) != type(list()):
            print(today[i])
    # printContent(data['today'])
